<?php

namespace Console\Controller;

use \Common\Controller\BaseController;

class LoginController extends BaseController {

    private $authLogic;

    public function _initialize() {
        parent::_initialize();
        $this->authLogic = A('Console/Auth', 'Logic');
    }

    public function index() {
        $this->display();
    }

    /**
     * 登陆
     */
    public function doLogin() {
        $phone = I('post.phone');
        $pwd = I('post.pwd');
        $saveLoginInfo = I('post.saveLoginInfo');

        $expire = "";
        if ($saveLoginInfo) {
            $expire = strtotime("+3 month");
        }

        $loginRes = $this->authLogic->login($phone, $pwd, $expire);
        unset($loginRes["Result"]);
        $this->ajaxReturn($loginRes);
    }

    /**
     * 登出
     */
    public function doLogout() {
        $this->authLogic->logout();
        $this->ajaxReturn(static::$res->suc("成功"));
    }

}
